//
//  WDGroMoreAdHelper.m
//  WDGroMore
//
//  Created by YeJary on 2025/5/22.
//

#import "WDGroMoreAdHelper.h"
#import <BUAdSDK/BUAdSDK.h>

@implementation WDGroMoreAdHelper

+ (NSDictionary *)ecpmInfoFromAd:(id)ad {
    if (!ad) return @{};

    id mediation = nil;

    if ([ad respondsToSelector:@selector(mediation)]) {
        mediation = [ad performSelector:@selector(mediation)];
    } else if ([ad respondsToSelector:@selector(valueForKey:)]) {
        @try {
            mediation = [ad valueForKey:@"mediation"];
        } @catch (NSException *e) {
            return @{};
        }
    }

    if (!mediation || ![mediation respondsToSelector:@selector(getCurrentBestEcpmInfo)]) return @{};

    BUMRitInfo *info = [mediation getCurrentBestEcpmInfo];
    if (!info) return @{};

    return @{
        @"ecpm": info.ecpm ?: @"0",
        @"adn": info.adnName ?: @"unknown",
        @"slotID": info.slotID ?: @"",
        @"requestID": info.requestID ?: @""
    };
}
@end
